﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MediatR;
using Common.Communal;
using ERP.Domain.Scheduling;
using Scheduling.Api.Read.Application.Command.CalendarCommand;

namespace Scheduling.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CalendarController : ControllerBase
    {
        private readonly IMediator _mediator;

        public CalendarController(IMediator mediator)
        {
            _mediator = mediator;
        }

        // 非分页查询（带条件）
        [HttpGet("list")]
        public async Task<ApiResult<List<Calendar>>> GetList(
            [FromQuery] DateTime? startDate,
            [FromQuery] DateTime? endDate,
            [FromQuery] bool? isWorkDay,
            [FromQuery] bool? isUrgentWorkday,
            [FromQuery] string? hoildayType,
            [FromQuery] string? reasonKeyword)
        {
            var cmd = new CalendarCreateCommand
            {
                StartDate = startDate,
                EndDate = endDate,
                IsWorkDay = isWorkDay,
                IsUrgentWorkday = isUrgentWorkday,
                HoildayType = hoildayType,
                ReasonKeyword = reasonKeyword
            };
            return await _mediator.Send(cmd);
        }

        // 按月查询
        [HttpGet("month")]
        public async Task<ApiResult<List<Calendar>>> GetByMonth(
            [FromQuery] int year,
            [FromQuery] int month,
            [FromQuery] bool? isWorkDay,
            [FromQuery] bool? isUrgentWorkday,
            [FromQuery] string? hoildayType,
            [FromQuery] string? reasonKeyword)
        {
            var cmd = new CalendarMonthQueryCommand
            {
                Year = year,
                Month = month,
                IsWorkDay = isWorkDay,
                IsUrgentWorkday = isUrgentWorkday,
                HoildayType = hoildayType,
                ReasonKeyword = reasonKeyword
            };
            return await _mediator.Send(cmd);
        }
    }
}
